﻿using Microsoft.Phone.Shell;
using ReferenceTemplate.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReferenceTemplate.WindowsPhone.Services
{
    public class TileService : ITileService
    {
        public void PintToStart(Models.Link link)
        {
            ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Id=" + link.Id));

            if (TileToFind == null)
            {
                StandardTileData NewTileData = new StandardTileData
                {
                    BackgroundImage = new Uri("/Assets/Images/" + link.Image, UriKind.Relative),
                    Title = link.Title,
                    BackContent = link.Title
                };

                ShellTile.Create(new Uri("/Views/DetailPage.xaml?Id=" + link.Id, UriKind.Relative), NewTileData);
            } 

        }

        public void UnpinToStart(Models.Link link)
        {
            throw new NotImplementedException();
        }

        public bool IsPinnedToStart(Models.Link link)
        {
            return true;
        }
    }
}
